#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/11/13 10:50
# @Author  : Yunhao.Cao
# @File    : logger.py
from __future__ import absolute_import, unicode_literals
import logging
import sys

__author__ = 'Yunhao.Cao'

__ALL__ = ["Logger", ]


class Logger:
    def __init__(self):
        pass

    ERROR = 40
    WARNING = 30
    INFO = 20
    DEBUG = 10

    @staticmethod
    def config(**kwargs):
        """
        配置参数
        - filename: 输出的文件名
        - level: 文件输出等级 default:INFO
        - format: 输出格式
        - datefmt: 输出时间的格式
        - console_level: 控制台输出等级 default=level
        :return:
        """
        level = kwargs.get("level", Logger.INFO)
        logging.basicConfig(**{
            "filename": kwargs.get("filename"),
            "level": level,
            "format": kwargs.get("format"),
            "datefmt": kwargs.get("datefmt")
        })
        sh = logging.StreamHandler(sys.stdout)
        sh.setFormatter(logging.Formatter(kwargs.get("format"), kwargs.get("datefmt")))
        sh.setLevel(kwargs.get("console_level") or level)
        logging.getLogger().addHandler(sh)

    @staticmethod
    def debug(msg):
        logging.debug(msg)

    @staticmethod
    def info(msg):
        logging.info(msg)

    @staticmethod
    def warning(msg):
        logging.warning(msg)

    @staticmethod
    def error(msg):
        logging.error(msg)


if __name__ == '__main__':
    pass
